<template>
    <div class="goodsinfo-container">
        <div class="mui-card">
            <div class="mui-card-content">
                <div class="mui-card-content-inner">
                    <swipe :lunboList="lunboList" :isfull="false"></swipe>
                </div>
            </div>
        </div>
        <div class="mui-card">
            <div class="mui-card-header">{{goodsInfo.title}}</div>
            <div class="mui-card-content">
                <div class="mui-card-content-inner">
                   <div class="price">
                       市场价：<span class="old">￥{{goodsInfo.market_price}}</span>
                       销售价：<span class="new">￥{{goodsInfo.sell_price}}</span>
                   </div>
                   <div class="number">购买数量：<numbox></numbox> </div>
                    <p>
                        <mt-button type="primary" size="small">立即购买</mt-button>
                        <mt-button type="danger" size="small">加入购物车</mt-button>
                    </p>
                </div>
            </div>
        </div>
        <div class="mui-card">
            <div class="mui-card-header">商品参数</div>
            <div class="mui-card-content">
                <div class="mui-card-content-inner">
                    <p>商品货号：{{goodsInfo.goods_no}}</p>
                    <p>库存情况：{{goodsInfo.stock_quantity}}件</p>
                    <p>上架时间：{{goodsInfo.add_time|dataFormat}}</p>
                </div>
            </div>
            <div class="mui-card-footer">
                <mt-button type="primary" size="large" plain @click="getDesc(goodsInfo.id)">图文介绍</mt-button>
                <mt-button type="danger" size="large" plain @click="getComment(goodsInfo.id)">商品评论</mt-button>
            </div>
        </div>

    </div>
</template>

<script>
    import swipe from "../subcomponents/Swipe.vue"
    import numbox from '../subcomponents/GoodsInfo_numberBox.vue'
    export default {
        name: "GoodsInfo",
        data(){
            return{
                id:this.$route.params.id,
                lunboList:[],
                goodsInfo:{}
            }
        },
        created(){
          this.getLunbotu();
          this.getGoodsInfo()
        },
        methods:{
            getLunbotu(){
                this.$http.get('api/getthumimages/'+this.id).then(result=>{
                    result.body.message.forEach(item=>{
                        item.img=item.src
                    })
                    this.lunboList=result.body.message;
                    // console.log(this.lunboList);
                })
            },
            getGoodsInfo(){
               this.$http.get("api/goods/getinfo/"+this.id).then(result=>{
                   console.log(result.body.message[0]);
                   this.goodsInfo=result.body.message[0];

               })
            },
            getDesc(id){
                this.$router.push({name:'goodsdesc',params:{id}})
            },
            getComment(id){
                this.$router.push({name:'goodscomment',params:{id}})
            }
        },
        components:{
            swipe,
            numbox
        }
    }
</script>

<style scoped>
.goodsinfo-container{
    background-color: #eee;
    overflow: hidden;
}
.goodsinfo-container .price{
    margin: 10px 0;
}
.goodsinfo-container .price .old{
    text-decoration: line-through;
    margin-right: 14px;
    font-size: 12px;
    color: #aaa;
}
.goodsinfo-container .price .new{
    color: red;
    font-size: 16px;
    font-weight: bold;
}
.goodsinfo-container .number{
    margin: 10px 0;
}
 .mui-card-footer{
     display: block;
 }
.mui-card-footer button{
    margin: 15px 0;
}
</style>